package me.xinping.libs.utils

import android.content.Context
import android.widget.Toast

/**
 * .
 * <p>
 * Date 2018/12/5
 * @author fanxinping_cd@keruyun.com
 */
class ToastHelper private constructor() {
    private var mToast: Toast? = null

    /**
     * 弹出默认toast
     *
     * @param context
     * @param content
     */
    private fun showToast(context: Context?, content: String) {
        if (context == null) {
            return
        }
        cancelToast()
        mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT)
        mToast!!.show()
    }

    private fun cancelToast() {
        if (mToast != null) {
            mToast!!.cancel()
            mToast = null
        }
    }

    companion object {
        private val instance: ToastHelper by lazy { ToastHelper() }

        fun showToast(context: Context?, content: String) {
            instance.showToast(context, content)
        }

        fun cancelToast() {
            instance.cancelToast()
        }
    }
}